# 生成 1 到 10 的列表
import math

a_list = [x for x in range(1, 11)]
print(a_list)

# 生成 1 到 10 的平方数
# a_list = [x**2 for x in range(1, 11)]
a_list = [math.pow(x, 2) for x in range(1, 11)]
print(a_list)

# 从字符串列表中过滤长度大于3的字符串
fruits = ['apple', 'banana', 'aaa', 'CCC']
filtered_fruits = [item for item in fruits if len(item) > 3]
print(filtered_fruits)

# 列表推导式的嵌套
numbers = [[i + j for i in range(3)] for j in range(4)]
print(numbers)
# 上面的代码相当于
lst = []
for j in range(4):
    j_list = []
    for i in range(3):
        j_list.append(i+j)
    lst.append(j_list)
print(lst)
# 一行代码输出乘法表
cfb = [[f"{i}*{j}={i * j}" for i in range(1,j+1)] for j in range(1, 10)]
for item in cfb:
    print(item)
